// pages/home-page/customer-tag/customerTag.js
// pages/home-page/project/project.js
const app = getApp()
const { baseUrl } = require('../../../utils/baseUrl.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    personalInfo: {},
    // url: 'https://xsfaappuat.cpic.com.cn/planbook/newPlanbook/index.html#/productDetail',
    url: `https://${baseUrl}/h5/#/`,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { customerId, origin } = options
    this.setData({
      customerId
    })
    console.log(`${this.data.url}customerTag?id=${customerId}&origin=${origin}&session=${wx.getStorageSync("token")}`)
    this.setData({
      url: `${this.data.url}customerTag?id=${customerId}&origin=${origin}&session=${wx.getStorageSync("token")}`,
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  train: function (params) {
    const { customerId, productId, productCode } = this.data
    app.api.post({
      url: 'customer_stage_add',
      data: {
        customerId,
        productId,
        stage: 'appointment' // appointment 约访训练，interview 面谈训练 
      }
    }).then(res => {
      wx.navigateTo({
        url: `/pages/home-page/appointment/appointment?customerId=${customerId}&productId=${productId}&productCode=${productCode}`
      })
    })
  },
  intervalGetImg () {
    const intervalId = setInterval(() => {
      app.api.post({
        url: 'customer_stage_getPlanResource',
        data: {
          customerId,
          productId
        }
      }).then(res => {
        if (res.data){
          clearInterval(this.data.intervalId)
          this.setData({
            imgUrl: res.data,
            webViewShow: false
          })
        }
      })
    }, 1000);
    this.setData({
      intervalId
    })
  }
})